home *** CD-ROM | disk | FTP | other *** search
/ Aminet 52 / Aminet 52 (2002)(GTI - Schatztruhe)[!][Dec 2002].iso / Aminet / misc / unix / unix_boot.lha / src / bind.c next >
Encoding:
C/C++ Source or Header  |  1991-12-09  |  1.4 KB  |  48 lines

  1. /*
  2.  *  Copyright (C) 1991, Commodore Business Machines, Inc.
  3.  *
  4.  *  Scan the system memory list and pick a suitable address as the
  5.  *  kernel start address.  Note that the space taken up by the MemHeader
  6.  *  itself is "missing" from the list, i.e., if it says memory starts at
  7.  *  0x280020, it really starts at 0x280000.  The missing 0x20 bytes are
  8.  *  where the MemHeader itself is stored.  Also note that the exception
  9.  *  vectors have been deleted from the chip memory (not that it matters),
  10.  *  and of course remember that you can't load the kernel into chip memory
  11.  *  anyway.
  12.  */
  13.  
  14. #pragma pack(2)
  15. #include <exec/types.h>
  16. #include <exec/memory.h>
  17. #include <exec/execbase.h>
  18. #include <exec/execname.h>
  19. #include <exec/libraries.h>
  20. #include <stdio.h>
  21. #pragma pack(4)
  22.  
  23. #define ABSEXECBASE ( (struct ExecBase **)4 )
  24.  
  25. unsigned long bind ()
  26. {
  27.     struct MemHeader *node;
  28.     unsigned long base = 0;
  29.     unsigned long maxsize = 0;
  30.     unsigned long size;
  31.  
  32.     for (node = (struct MemHeader *) (*ABSEXECBASE) -> MemList.lh_Head;
  33.      node -> mh_Node.ln_Succ;
  34.      node = (struct MemHeader *) node -> mh_Node.ln_Succ)
  35.     {
  36.     if (!(node -> mh_Attributes & MEMF_CHIP)) {
  37.             size = (unsigned long) (node -> mh_Upper);
  38.         size -= (unsigned long) (node -> mh_Lower) & ~0xFF;
  39.         if (size > maxsize) {
  40.         maxsize = size;
  41.         base = (unsigned long) (node -> mh_Lower) & ~0xFF;
  42.         }
  43.     }
  44.     }
  45.     return (base);
  46. }
  47.  
  48.